package com.pay.game.central.web.service;

import org.springframework.stereotype.Component;


import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Component
public class DeviceService {
    private ConcurrentMap<String, Long> deviceStatus = new ConcurrentHashMap<>();

    public void updateOnlineTime(String realName){
        deviceStatus.put(realName, System.currentTimeMillis());
    }

    public Set<String> getOnlineDevice(){
        Set<String> rst = new HashSet<>();
        long currentTime = System.currentTimeMillis();
        deviceStatus.forEach((key,value)->{
            if (currentTime - value < 11 * 1000){
                rst.add(key);
            }
        });
        return rst;
    }

}
